package com.macro.mall.tiny.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Spring MVC 配置
 * Created by macro on 2024/1/15.
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload.path:uploads/images/}")
    private String uploadPath;

    @Value("${file.editor.upload.path:uploads/editor/}")
    private String editorUploadPath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置普通图片上传路径映射
        registry.addResourceHandler("/uploads/images/**")
                .addResourceLocations("file:" + uploadPath);

        // 配置富文本编辑器上传路径映射
        registry.addResourceHandler("/uploads/editor/**")
                .addResourceLocations("file:" + editorUploadPath);
    }
}